package info.unclewang.bert.support.dao;

import info.unclewang.bert.support.dataObject.CitationsDO;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.query.NativeQuery;

import java.util.List;
import java.util.stream.Stream;

/**
 * @author unclewang
 * @date 2019/9/7 18:51
 */
public class CitationsDAO {
	private Configuration config = null;
	private SessionFactory sessionFactory = null;
	private Session session = null;
	private Transaction tx = null;

	public void init() {
		config = new Configuration().configure("/hibernate.cfg.xml");
		sessionFactory = config.buildSessionFactory();
		session = sessionFactory.openSession();
		tx = session.beginTransaction();
	}

	public void test() {
		this.init();
		NativeQuery nativeQuery = this.session.createSQLQuery("select * from citations");
		Stream resultStream = nativeQuery.addEntity(CitationsDO.class).getResultStream();
		resultStream.forEach(o -> {
			System.out.println((CitationsDO)o);
			System.exit(1);
		});


//		for (int i = 0; i < 48; i++) {
//			nativeQuery.setParameter(1, i * 1000);
//			nativeQuery.setParameter(2, (i + 1) * 1000);
//			List list = nativeQuery.addEntity(CitationsDO.class).getResultList();
//
//			System.out.println(list.size());
//			list.clear();
////			break;
//		}


	}

	public static void main(String[] args) {
		CitationsDAO citationsDAO = new CitationsDAO();
		citationsDAO.test();

	}
}
